#ifndef SECURITYAUDITOR_H
#define SECURITYAUDITOR_H

#include <fstream>
#include <string>
#include <chrono>
#include <mutex>
#include "include/nlohmann/json.hpp"

// 审计事件类型
enum class AuditEventType {
    AUTHENTICATION_SUCCESS,
    AUTHENTICATION_FAILURE,
    DATA_ACCESS,
    CONFIGURATION_CHANGE,
    SYSTEM_EVENT,
    ALARM_TRIGGERED,
    ALARM_CLEARED
};

// 安全审计器类
class SecurityAuditor {
private:
    std::ofstream logFile;
    std::string logPath;
    std::string logLevel;
    std::mutex logMutex;
    bool isEnabled;

    // 将事件类型转换为字符串
    std::string eventTypeToString(AuditEventType type);

    // 获取当前时间戳
    std::string getCurrentTimestamp();

public:
    // 构造函数与析构函数
    SecurityAuditor(const std::string& configPath);
    ~SecurityAuditor();

    // 初始化审计器
    bool initialize();

    // 记录审计事件
    void logEvent(AuditEventType type, const std::string& user, const std::string& details);

    // 检查日志级别
    bool shouldLog(const std::string& level);

    // 启用/禁用审计
    void enable(bool enabled) { isEnabled = enabled; }
    bool enabled() const { return isEnabled; }
};

#endif // SECURITYAUDITOR_H